<template>
    <el-container class="admin-container">
        <el-header class="admin-header">
            <div class="header-content">
                <div class="logo-section">
                    <span class="logo-text">豹饱巴士外卖系统</span>
                </div>
                <div class="welcome-section">
                    <el-dropdown>
                        <span class="welcome-text">
                            <el-avatar :icon="UserFilled" size="small" class="user-avatar" />
                            骑手 <i class="el-icon-arrow-down el-icon--right"></i>
                        </span>
                        <template #dropdown>
                            <el-dropdown-menu>
                                <el-dropdown-item @click="$router.push('/rider/profile')">
                                    <el-icon><User /></el-icon>个人中心
                                </el-dropdown-item>
                                <el-dropdown-item divided @click="logout">
                                    <el-icon><SwitchButton /></el-icon>退出登录
                                </el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
                </div>
            </div>
        </el-header>
        <el-container class="main-container">
            <el-aside class="sidebar">
                <el-scrollbar>
                    <div class="user-profile">
                        <el-avatar :src="riderAvatar" :size="80" class="profile-avatar" />
                        <h3 class="user-name">骑手</h3>
                        <div class="online-status">
                            <span class="status-indicator"></span>
                            <span class="status-text">在线</span>
                        </div>
                    </div>

                    <el-menu
                        :default-active="activeMenu"
                        :router="true"
                        class="sidebar-menu"
                        background-color="transparent"
                        text-color="#333"
                        active-text-color="#409EFF"
                    >
                        <el-menu-item index="/rider/profile" class="menu-item">
                            <el-icon><User /></el-icon>
                            <span>个人信息</span>
                        </el-menu-item>

                        <el-sub-menu index="orders" class="menu-group">
                            <template #title>
                                <el-icon><Document /></el-icon>
                                <span>订单管理</span>
                            </template>
                            <el-menu-item index="/rider/ordering" class="submenu-item">
                                <el-icon><Bicycle /></el-icon>
                                <span>正在进行</span>
                            </el-menu-item>
                            <el-menu-item index="/rider/completed" class="submenu-item">
                                <el-icon><ShoppingCart /></el-icon>
                                <span>已完成订单</span>
                            </el-menu-item>
                        </el-sub-menu>

                        <el-sub-menu index="settings" class="menu-group">
                            <template #title>
                                <el-icon><Setting /></el-icon>
                                <span>系统设置</span>
                            </template>
                            <el-menu-item index="/config" class="submenu-item">
                                <el-icon><Tools /></el-icon>
                                <span>系统配置</span>
                            </el-menu-item>
                        </el-sub-menu>
                    </el-menu>
                </el-scrollbar>
            </el-aside>
            <el-main class="main-content">
                <!-- 路由显示区 -->
                <router-view />
            </el-main>
        </el-container>
    </el-container>
</template>

<style scoped>
.admin-container {
    height: 100vh;
    background-color: #f5f7fa;
}

.admin-header {
    background: linear-gradient(90deg, #2c3e50, #4a6491);
    color: white;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    padding: 0 20px;
}

.logo-section {
    display: flex;
    align-items: center;
}

.logo-text {
    font-size: 24px;
    font-weight: bold;
    letter-spacing: 1px;
}

.welcome-section {
    display: flex;
    align-items: center;
}

.welcome-text {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
}

.user-avatar {
    margin-right: 10px;
    background-color: #409EFF;
}

.main-container {
    height: calc(100vh - 60px);
}

.sidebar {
    width: 240px;
    background: linear-gradient(180deg, #ffffff, #f8f9fa);
    border-right: 1px solid #e6e6e6;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
    padding: 20px 0;
}

.user-profile {
    text-align: center;
    padding: 20px 0;
    border-bottom: 1px solid #eee;
    margin-bottom: 20px;
}

.profile-avatar {
    margin-bottom: 15px;
    border: 3px solid #409EFF;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.user-name {
    margin: 0 0 10px 0;
    font-size: 18px;
    color: #333;
}

.online-status {
    display: flex;
    justify-content: center;
    align-items: center;
}

.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #5CB85C;
    margin-right: 5px;
}

.status-text {
    font-size: 14px;
    color: #666;
}

.sidebar-menu {
    border: none;
}

.menu-item,
.submenu-item {
    border-radius: 6px;
    margin: 5px 10px;
    transition: all 0.3s;
}

.menu-item:hover,
.submenu-item:hover {
    background-color: #e6f2ff;
    transform: translateX(5px);
}

.menu-group {
    margin: 10px 0;
}

.menu-group :deep(.el-sub-menu__title) {
    border-radius: 6px;
    margin: 0 10px;
    transition: all 0.3s;
}

.menu-group :deep(.el-sub-menu__title):hover {
    background-color: #e6f2ff;
    transform: translateX(5px);
}

.menu-group :deep(.el-sub-menu__title) .el-icon {
    color: #409EFF;
}

.main-content {
    padding: 20px;
    background-color: #f5f7fa;
    overflow: auto;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .sidebar {
        width: 180px;
    }

    .logo-text {
        font-size: 20px;
    }

    .user-name {
        font-size: 16px;
    }
}
</style>

<script setup>
import { ref, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { User, UserFilled, SwitchButton, Document, Bicycle, ShoppingCart, Setting, Tools } from '@element-plus/icons-vue'

// 导入骑手头像
import riderAvatar from '../../assets/rider.jpg'

const route = useRoute()
const router = useRouter()

// 当前激活菜单
const activeMenu = computed(() => {
    const { meta, path } = route
    if (meta.activeMenu) {
        return meta.activeMenu
    }
    return path
})

// 退出登录
const logout = () => {
    // 清除登录信息
    localStorage.removeItem('riderId')
    sessionStorage.removeItem('riderId')
    // 跳转到登录页
    router.push('/multilogin')
}
</script>
